package io.zt.dangyuan;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import io.zt.dangyuan.customView.SendEvent;

import butterknife.ButterKnife;
import butterknife.InjectView;
import de.greenrobot.event.EventBus;

public class MenuLeftFragment extends Fragment {

    String[] titles = {"首页", "党建动态", "通知公告", "工作部署", "两学一做", "志愿活动", "三会一课", "支部活动", "我的管理", "心理解析"};
    @InjectView(R.id.menu_list)
    ListView menuList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_menu_left, container, false);
        ButterKnife.inject(this, view);
        initData();
        initEvents();
        return view;
    }

    private void initData() {
        menuList.setAdapter(new SimpleItemAdapter(this.getActivity(), titles));
    }

    private void initEvents() {
        menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                int intentPos=0;
                switch (position) {
                    case 0:
                        startActivity(new Intent(MenuLeftFragment.this.getActivity(), MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                        return;
                    case 8://判断，未登录跳转登陆，登陆跳转管理

                        final GlobalDataApplication app = (GlobalDataApplication)MenuLeftFragment.this.getActivity().getApplication();

                        if (app.getUserModel()!=null)
                        {
                            startActivity(new Intent(MenuLeftFragment.this.getActivity(), MyAdminActivity.class));
                        }else
                        {
                            startActivity(new Intent(MenuLeftFragment.this.getActivity(), LoginActivity.class));
                        }

//                        startActivity(new Intent(MenuLeftFragment.this.getActivity(), MyAdminActivity.class));
                        return;
                    case 1:intentPos=6; break;
                    case 2:intentPos=5; break;
                    case 3:intentPos=7; break;
                    case 4:intentPos=2; break;
                    case 5:
                        startActivity(new Intent(MenuLeftFragment.this.getActivity(), ReadLove.class));
                        return;

                    case 6:intentPos=4; break;
                    case 7:intentPos=1; break;
                    case 9:intentPos=0; break;
                }
                switch (intentPos) {
                    case 5://团青时讯
                        startActivity(new Intent(MenuLeftFragment.this.getActivity(), ActivityItem2.class).putExtra("pos", intentPos).putExtra("titles", MainActivity.title_TQ));
                        break;
                    case 6://党建动态
                        startActivity(new Intent(MenuLeftFragment.this.getActivity(), ActivityItem1.class).putExtra("pos", intentPos));
                        break;
                    case 7://工作部署
                        startActivity(new Intent(MenuLeftFragment.this.getActivity(), ActivityItem1.class).putExtra("pos", intentPos));
                        break;
                    case 0://青年心理一解一
                        startActivity(new Intent(MenuLeftFragment.this.getActivity(), ActivityItem2.class).putExtra("pos", intentPos).putExtra("titles", MainActivity.title_QN));
                        break;
                    case 1://活动超市
                        startActivity(new Intent(MenuLeftFragment.this.getActivity(), ActivityItem2.class).putExtra("pos", intentPos).putExtra("titles", MainActivity.title_HD));
                        break;
                    case 2://众筹公益
                        startActivity(new Intent(MenuLeftFragment.this.getActivity(), ActivityItem1.class).putExtra("pos", intentPos));
                        break;
                    case 4:
                        startActivity(new Intent(MenuLeftFragment.this.getActivity(), ActivityLife.class));
                        break;
                }

            }
        });
        EventBus.getDefault().post(new SendEvent(1));
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }




}
